//
//  YJSpecificationController.m
//  SnackCourier
//
//  Created by qianfeng01 on 15/7/21.
//  Copyright (c) 2015年 qianfeng01. All rights reserved.
//

#import "YJSpecificationController.h"
#import "AFNetworking.h"

@interface YJSpecificationController ()

@property (nonatomic,strong) AFHTTPRequestOperationManager *manager;
@property (nonatomic,strong) UITextView *textView;

@end

@implementation YJSpecificationController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
}

-(void)initData{
    self.textView =[[UITextView alloc] initWithFrame:CGRectMake(10, 10, self.view.frame.size.width-10, self.view.frame.size.height)];
    self.textView.textAlignment =NSTextAlignmentLeft;
    self.textView.font =[UIFont systemFontOfSize:12];
    self.textView.scrollEnabled =NO;
    self.textView.editable =NO;
    self.manager =[AFHTTPRequestOperationManager manager];
    self.manager.responseSerializer =[AFHTTPResponseSerializer serializer];
    __weak typeof (self)weakSelf=(self);
    [self.manager GET:self.urlStr parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (responseObject) {
            NSDictionary *dicts =[NSJSONSerialization JSONObjectWithData:responseObject options:(NSJSONReadingMutableContainers) error:nil];
            NSDictionary *data =dicts[@"data"];
            NSArray *array =data[@"spec"];
            if (array.count!=0) {
                NSString *specStr =[array componentsJoinedByString:@"\n"];
                weakSelf.textView.text =specStr;
                [weakSelf.view addSubview:self.textView];
            }else{
                
                weakSelf.textView.text =@"无";
                [weakSelf.view addSubview:weakSelf.textView];
            }
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
